package com.webapp.db;

import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;

import com.webapp.util.BaseLog;

public class DBconnection extends BaseLog
{
  private static String classname = "oracle.jdbc.driver.OracleDriver";
  private static String url = "jdbc:oracle:thin:@199.28.178.41:1521:oracle";
  private static String user = "CN_HKRX_DMS";
  private static String password = "CN_HKRX_DMS";

  public static Connection getConnection() {
    try {
      Class.forName(classname);
      return DriverManager.getConnection(url, user, password);
    }
    catch (ClassNotFoundException e) {
      logger.info("Errors in method getConnection() of class DBconnection:");
      logger.error(e);
    }
    catch (SQLException e) {
      logger.info("Errors in method getConnection() of class DBconnection:");
      logger.error(e);
    }
    return null;
  }

  public static void closeAll(Connection conn, Statement stmt, PreparedStatement pstmt, ResultSet rs) throws SQLException {
    if (rs != null)
      rs.close();
    if (pstmt != null)
      pstmt.close();
    if (stmt != null)
      stmt.close();
    if (conn != null)
      conn.close();
  }

  public static void main(String[] args)
  {
    System.out.println(getConnection());
  }
}